package com.qdlc.p2p.biz.tpp.model;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.qdlc.p2p.common.constant.SinaConstant;
import com.qdlc.p2p.common.util.DateUtil;
import com.qdlc.p2p.common.util.StringUtil;

/**
 * 新浪 - 查询银行卡信息
 * @author gcx
 * @version 2.0
 * @date 2015年8月13日上午10:57:03
 */
public class SinaQueryBankCard extends SinaModel{

	/**
	 * 卡ID
	 */
	private String card_id;
	/**
	 * 扩展信息
	 */
	private String extend_param;

	/**
	 * 待签名字符数组
	 */
	private String[] signParamNames=new String[]{"version","service","request_time","partner_id","_input_charset","identity_id","identity_type"};

	/**
	 * 提交字符数组
	 */
	private String[] subParamNames=new String[]{"version","service","request_time","partner_id","_input_charset","identity_id","identity_type","sign","sign_type"};

	/******** 响应信息 start ********/

	/**
	 *	卡列表
	 */
	private String card_list;

	/******** 响应信息 end ********/

	public SinaQueryBankCard() {
		super();
	}

	public SinaQueryBankCard(String card_id,String extend_param, String identity_id) {
		super();
		this.setRequest_time(DateUtil.dateStr3(DateUtil.getNow()));
		this.setIdentity_id(identity_id);
		this.setIdentity_type(SinaConstant.IDENTITY_TYPE_UID);
		this.card_id = card_id;
		this.extend_param= extend_param;
		this.setService("query_bank_card");
		this.setEncode(SinaConstant.ENCODE_FALSE);
	}

	@Override
	public SinaModel response(String res) throws IOException {
		try {
			JSONObject json = JSON.parseObject(res);
			card_list = json.getString("card_list");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public List<SinaBankCard> getSinaBankList(String cardListStr){
		List<SinaBankCard> bankCardList = new ArrayList<SinaBankCard>();
		if(StringUtil.isBlank(cardListStr)){
			return bankCardList;
		}

		if(cardListStr.contains("|")){
			String [] bankCardArr =  cardListStr.split("|");
			for (int i = 0; i < bankCardArr.length; i++) {
				SinaBankCard bankCard = getSinaBankCard(cardListStr);
				bankCardList.add(bankCard);
			}
		}else{
			SinaBankCard bankCard = getSinaBankCard(cardListStr);
			bankCardList.add(bankCard);
		}
		return bankCardList;
	}

	private SinaBankCard getSinaBankCard(String bankCardStrArr){
		SinaBankCard bankCard = new SinaBankCard();
		String [] cardArr = bankCardStrArr.split("\\^");
		bankCard.setCardId(cardArr[0]);
		bankCard.setBankCode(cardArr[1]);
		bankCard.setBankAccountNo(cardArr[2]);
		bankCard.setAccountName(cardArr[3]);
		bankCard.setCardType(cardArr[4]);
		bankCard.setCardAttribute(cardArr[5]);
		bankCard.setVerifyMode(cardArr[6]);
		bankCard.setRequestTime(cardArr[7]);
		bankCard.setIsVerified(cardArr[8]);
		return bankCard;

	}

	public String getCard_id() {
		return card_id;
	}
	public void setCard_id(String card_id) {
		this.card_id = card_id;
	}
	public String getExtend_param() {
		return extend_param;
	}
	public void setExtend_param(String extend_param) {
		this.extend_param = extend_param;
	}
	public String[] getSignParamNames() {
		return signParamNames;
	}
	public void setSignParamNames(String[] signParamNames) {
		this.signParamNames = signParamNames;
	}
	public String[] getSubParamNames() {
		return subParamNames;
	}
	public void setSubParamNames(String[] subParamNames) {
		this.subParamNames = subParamNames;
	}
	public String getCard_list() {
		return card_list;
	}
	public void setCard_list(String card_list) {
		this.card_list = card_list;
	}

}
